package Tasks;

import Plants.PowerPlant;

/**
 * Sends energy from one plant to another
 * @author jeffrey
 *
 */
public class SendEnergy extends MyRunnable{

	PowerPlant source;
	PowerPlant destination;
	int amount;
	
	public SendEnergy(PowerPlant source, PowerPlant destination, int amount)
	{
		this.source = source;
		this.destination = destination;
		this.amount = amount;
	}
	
	@Override
	public synchronized void run()
	{
		if(super.haltExecution()) return;
		source.incrementAvailableEnergy(-amount, true);
		//Would like to be able to model energy loss due to distance
		destination.incrementAvailableEnergy(amount, true);
	}
	
	@Override
	public String toString()
	{
		return "Send " + amount + " energy from " + source.getName() + " to " + destination.getName();
	}
	
}
